import excel "anonymized.xlsx", sheet("Limits+of+Extra-judicial,+more_") firstrow case(lower) clear


** remove researcher created entries
drop if distribution == "preview"
drop if distribution == "test"
drop startdate-userlanguage

** indicators for random assignment
gen notability = .
replace notability = 0 if random != 1
replace notability = 1 if random == 1

gen pidassoc = .
replace pidassoc = 0 if random2 == 0
replace pidassoc = 1 if random2 == 1

** notability 
* rescale 1-5 (instead of 17-21)
foreach var of varlist q166_1-q166_12{
	replace `var' = `var' - 16
}
*
gen notaCooper = q166_1
gen notaRush = q166_2
gen notaMaddow = q166_3
gen notaOreilly = q166_4
gen notaRomney = q166_5
gen notaSchumer = q166_6
gen notaScalice = q166_7
gen notaPressley = q166_8
gen notaBarr = q166_9
gen notaGabbard = q166_10
gen notaHickenlooper = q166_11
gen notaWeld = q166_12

*** predispositions
gen pid1 = q52
gen pid2rep = q54
gen pid2dem = q56
gen pid2ind = q58

gen pid = -3 if pid2dem == 1
replace pid = -2 if pid2dem == 2
replace pid = -1 if pid2ind == 2
replace pid = 0 if pid2ind == 3
replace pid = 0 if pid2ind == 4
replace pid = 1 if pid2ind == 1
replace pid = 2 if pid2rep == 2
replace pid = 3 if pid2rep == 1

gen pid3 = .
replace pid3 = 1 if pid < 0
replace pid3 = 2 if pid == 0
replace pid3 = 3 if pid > 0 & pid < .

*** figure's partisan association
gen trumpAssoc = q168_1
gen scaliceAssoc = q168_2
gen pressleyAssoc = q168_3
gen pelosiAssoc = q168_4
gen barrAssoc = q168_5
gen gabbardAssoc = q168_6
gen hickenlooperAssoc = q168_7
gen weldAssoc = q168_8


foreach var of varlist trumpAssoc-weldAssoc{
	gen `var'2 = `var'
	replace `var'2 = . if `var' == 4
}
*


foreach var of varlist trumpAssoc-weldAssoc{
	gen `var'DK = .
	replace `var'DK = 0 if `var' == 1 
	replace `var'DK = 0 if `var' == 2 
	replace `var'DK = 0 if `var' == 3 
	replace `var'DK = 1 if `var' == 4
}
*

*** initial legitimacy score

alpha q2_1-q2_7, gen(origLegit)

*** treatments 
* control 
alpha q119_1-q119_7, gen(controlLegit)
alpha q123-q135, gen(weldLegit)
alpha q141-q147, gen(hickenlooperLegit)
alpha ce-ck, gen(gabbardLegit)
alpha cl-q139, gen(barrLegit)
alpha q117-cy, gen(pressleyLegit)
alpha q149-q155, gen(scaliceLegit)

foreach v of var origLegit-scaliceLegit{
	su `v', meanonly 
	replace `v' = (`v' - r(min))/(r(max) - r(min)) 
}
*

*** dependent variable; change in diffuse support
foreach var of varlist controlLegit-scaliceLegit{
	gen `var'Diff = (`var'-origLegit)
}	
*


gen treatment = . 
replace treatment = 0 if controlLegit != .
replace treatment = 1 if weldLegit != .
replace treatment = 2 if hickenlooperLegit != .
replace treatment = 3 if gabbardLegit != .
replace treatment = 4 if barrLegit != .
replace treatment = 5 if pressleyLegit != .
replace treatment = 6 if scaliceLegit != .

label define treatment 0 "Control" 1 "Weld"  2 "Hickenlooper" ///
	3 "Gabbard" 4 "Barr" 5 "Pressley" 6 "Scalice"
label values treatment treatment



*** FTs

gen trumpAffect = q50_1
gen scaliceAffect = q50_18
gen pressleyAffect = q50_19
gen pelosiAffect = q50_2
gen barrAffect = q50_3
gen gabbardAffect = q50_4
gen hickenlooperAffect = q50_23
gen weldAffect = q50_24

foreach var of varlist trumpAffect-weldAffect{
	gen `var'2 = .
	replace `var'2 = 1 if `var' >= 0 & `var' <=10
	replace `var'2 = 2 if `var' > 10 & `var' <=20
	replace `var'2 = 3 if `var' > 20 & `var' <=30
	replace `var'2 = 4 if `var' > 30 & `var' <=40
	replace `var'2 = 5 if `var' > 40 & `var' <=50
	replace `var'2 = 6 if `var' > 50 & `var' <=60
	replace `var'2 = 7 if `var' > 60 & `var' <=70
	replace `var'2 = 8 if `var' > 70 & `var' <=80
	replace `var'2 = 9 if `var' > 80 & `var' <=90
	replace `var'2 = 10 if `var' > 90 & `var' <=100
	}	
*



*** analysis


reg weldLegitDiff weldAffect2, beta
margins, at(weldAffect2 = (1(1)10))

reg hickenlooperLegitDiff hickenlooperAffect2, beta
margins, at(hickenlooperAffect2 = (1(1)10))

reg gabbardLegitDiff gabbardAffect2, beta 
margins, at(gabbardAffect2 = (1(1)10))

reg barrLegitDiff barrAffect2, beta 
margins, at(barrAffect2 = (1(1)10))

reg pressleyLegitDiff c.pressleyAffect2, beta 
margins, at(pressleyAffect2 = (1(1)10))

reg scaliceLegitDiff scaliceAffect2, beta 
margins, at(scaliceAffect2 = (1(1)10))


*** affect effect on control
reg controlLegit weldAffect2 hickenlooperAffect2 gabbardAffect2 barrAffect2 ///
	pressleyAffect2 scaliceAffect2

	
******** partisan association

pc: import excel "anonymized3.xlsx", sheet("Limits+of+Extra-judicial,+EVEN+") firstrow case(lower)


drop startdate-userlanguage

gen nCooper = q166_1
gen nLimbaugh = q166_2
gen nMaddow = q166_3
gen nOreilly = q166_4
gen nRomney = q166_5
gen nSchumer = q166_6
gen nScalice = q166_7
gen nPressley = q166_8
gen nBarr = q166_9
gen nGabbard = q166_10
gen nHickenlooper = q166_11
gen nWeld = q166_12

foreach var of varlist nCooper-nWeld{
	replace `var' = `var' - 16
}
*

gen dkTrump = 0
gen dkScalice = 0
gen dkPressley = 0
gen dkPelosi = 0
gen dkBarr = 0
gen dkGabbard = 0
gen dkHickenlooper = 0
gen dkWeld = 0
gen dkRomney = 0
gen dkCooper = 0
gen dkOreilly = 0
gen dkLimbaugh = 0
gen dkSchumer = 0
gen dkMaddow = 0

replace dkTrump = 1 if q168_1 == 4
replace dkScalice = 1 if q168_2 == 4
replace dkPressley = 1 if q168_3 == 4
replace dkPelosi = 1 if q168_4 == 4
replace dkBarr = 1 if q168_5 == 4
replace dkGabbard = 1 if q168_6 == 4
replace dkHickenlooper = 1 if q168_7 == 4
replace dkWeld = 1 if q168_8 == 4
replace dkRomney = 1 if q168_9 == 4
replace dkCooper = 1 if q168_10 == 4
replace dkOreilly = 1 if q168_11 == 4
replace dkLimbaugh = 1 if q168_12 == 4
replace dkSchumer = 1 if q168_13 == 4
replace dkMaddow = 1 if q168_14 == 4

mean nCooper-nWeld
sum dkCooper dkLimbaugh dkMaddow dkOreilly dkRomney dkSchumer ///
	dkScalice dkPressley dkBarr dkGabbard dkHickenlooper dkWeld

	
gen corTrump = 0
gen corScalice = 0
gen corPressley = 0
gen corPelosi = 0
gen corBarr = 0
gen corGabbard = 0
gen corHickenlooper = 0
gen corWeld = 0
gen corRomney = 0
gen corCooper = 0
gen corOreilly = 0
gen corLimbaugh = 0
gen corSchumer = 0
gen corMaddow = 0

replace corTrump = 1 if q168_1 == 3
replace corScalice = 1 if q168_2 == 3
replace corPressley = 1 if q168_3 == 1
replace corPelosi = 1 if q168_4 == 1
replace corBarr = 1 if q168_5 == 3
replace corGabbard = 1 if q168_6 == 1
replace corHickenlooper = 1 if q168_7 == 1
replace corWeld = 1 if q168_8 == 3
replace corRomney = 1 if q168_9 == 3
replace corCooper = 1 if q168_10 == 1
replace corOreilly = 1 if q168_11 == 3
replace corLimbaugh = 1 if q168_12 == 3
replace corSchumer = 1 if q168_13 == 1
replace corMaddow = 1 if q168_14 == 1

mean corCooper corLimbaugh corMaddow corOreilly corRomney corSchumer ///
	corScalice corPressley corBarr corGabbard corHickenlooper corWeld		


